package cn.moningxi.controller;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 全局异常处理
 */
@ControllerAdvice
public class GlobalExceptionController {

    /**
     * 用户未登录处理
     *
     * @param n
     * @return
     */
    @ExceptionHandler(NullPointerException.class)
    public String noLoginException(NullPointerException n) {
        System.out.println("错误信息====" + n.getMessage());
        if (n.getMessage().contains("\"onlineUser\" is null") || n.getMessage().contains("\"loginUser\" is null")) {
            //未登录 跳转登录页面
            return "redirect:/static/business/home/login.jsp";
        } else {
            return "business/403";
        }
    }
}
